home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-01.zip / 01 / Hity z okladki / OrgPlus 6 SBE / ORGPL.CAB / profilePage.js < prev    next >
Text File  |  2006-09-20  |  7KB  |  234 lines

  1. /**********************************************************
  2. *                                                         *
  3. * (C) Copyright 2002 - 2004,  Human Concepts (tm)         *
  4. *                                                         *
  5. ***********************************************************
  6. * File name: profilePage.js                               *
  7. * Author: Andrey Ponomarev                                *
  8. **********************************************************/
  9.  
  10. window.onload = doInit;
  11.  
  12. function Initialize()
  13. {
  14.   if( ListObject != null )
  15.     return;
  16.   var width = parseInt(document.body.clientWidth);
  17.   var col = parseInt(width) / 3;
  18.   ListObject = new ListCtrl(document.body);
  19.   ListObject.AddColumn("<b>Field</b>");
  20.   ListObject.AddColumn("<b>Value</b>");
  21.   ListObject.Columns[0].SetWidth( col );
  22.   ListObject.Columns[1].SetWidth( width - col );
  23.   ListObject.HighlightColor = "#CCCCFF";
  24. }
  25.  
  26. function doInit()
  27. {
  28.   Initialize();
  29.   
  30.   var obj = top.hcMain
  31.   if ( typeof (obj) == "object" && typeof (obj.onNavigatePageInit) != "undefined" )
  32.     obj.onNavigatePageInit()
  33. }
  34.  
  35. function clearPage()
  36. {
  37.   ListObject.ClearTable();
  38.   ListObject.RemoveAll();
  39. }
  40.  
  41. function LoadOldProfile(group)
  42. {
  43.   if( typeof( group ) != "object" )
  44.     return;
  45.   
  46.   var ancObjs = group.getElementsByTagName("a")
  47.   for (i = 0; i < ancObjs.length; i++)
  48.   {
  49.     if( ancObjs(i).name != "Profile")
  50.       continue;
  51.  
  52.     var paramObjs = ancObjs(i).getElementsByTagName("param")
  53.     for (j = 0; j < paramObjs.length; j++)
  54.     {
  55.       var obj = paramObjs(j)
  56.       var str = obj.name
  57.       if (typeof(str) != "undefined" )
  58.       {
  59.         var strValue = ""
  60.         if ( typeof (obj.value) != "undefined" )
  61.           strValue = obj.value
  62.  
  63. //      if (!bImageFlag && isEmail(strValue))
  64. //        strValue = "<a href='mailto:" + strValue + "'>" + strValue + "</a>";  
  65.         if( typeof(obj.IsPicture) != 'undefined' && obj.IsPicture == "true" && strValue != "" && strValue != " ")
  66.           strValue = "<img src='" + strValue + "'/>";
  67.  
  68.         var newRow = null;
  69.         newRow = new Array( new ListCtlCell(str, 1), new ListCtlCell(strValue, 1) );
  70.         ListObject.Add( newRow );
  71.       }
  72.     } //for
  73.     break;
  74.   } //for 
  75. };
  76.  
  77. function fillPage(group)
  78. {
  79.   if( ListObject == null )
  80.     Initialize();
  81.         debugger;
  82.     
  83.   clearPage()
  84.   
  85.   var ProfileData = top.hcMain.getProfilesObj();
  86.   
  87.   if( typeof( group ) != "object" )
  88.     return;
  89.     
  90.   var oProfile = ProfileData.children[0];
  91.   
  92.   if( typeof( oProfile.type ) != 'undefined' && parseInt( oProfile.type ) == 2 && g_gIEVer == 60 )
  93.   {
  94.     ShowHTMLProfile( oProfile, group );
  95.     return;
  96.   }
  97.   
  98.   var oData = top.hcPersons.document.all[ group.id ];
  99.   
  100.   if( oData == null ) return;
  101.   if( typeof( oProfile.type ) != 'undefined' && parseInt( oProfile.type ) == 2 && g_gIEVer < 60 )
  102.     LoadOldProfile(group);
  103.   else
  104.   {
  105.     if( typeof( oProfile.ShowGrid) == 'undefined' || oProfile.ShowGrid == 1 || oProfile.ShowGrid == "1" )
  106.       ListObject.ShowGrid( true );
  107.     else
  108.       ListObject.ShowGrid( false );
  109.     
  110.     for( var i = 0; i < oProfile.children.length; ++i )
  111.     {
  112.       var oParam = oProfile.children[i];
  113.       
  114.       if( oParam.tagName != "PARAM" )
  115.         continue;
  116.       
  117.       var leftText = oParam.Name;
  118.       
  119.       if( typeof( oParam.LeftWordWrap ) != 'undefined' && (oParam.LeftWordWrap == 0 || oParam.LeftWordWrap == "0") )
  120.         leftText = "<NOBR>" + leftText + "</NOBR>";
  121.       
  122.       if( typeof( oParam.LeftStyle ) != 'undefined' )
  123.         leftText = oParam.LeftStyle + leftText + "</font>";
  124.  
  125.       var rightText;
  126.       if( typeof( oParam.FieldId ) != 'undefined' )
  127.       {
  128.         groupValue = oData.children[fi];
  129.         for( var fi = 0; fi < oData.children.length; ++fi )
  130.           if( oData.children[fi].tagName == "PARAM" && oData.children[fi].id == oParam.FieldId )
  131.           {
  132.             groupValue = oData.children[fi];
  133.             break;
  134.           };
  135.         
  136.         rightText = groupValue.name;
  137.         if( typeof( oParam.IsPicture ) != 'undefined' && oParam.IsPicture == 1 && rightText != "" )
  138.           rightText = "<img src=\"" + rightText + "\">";
  139.         
  140.         if( typeof( oParam.IsLink ) != 'undefined' && oParam.IsLink == 1 )
  141.         {
  142.           var strURL = groupValue.value;
  143.           if( typeof( strURL ) == 'undefined' )
  144.             strURL = groupValue.name;
  145.           
  146.           if( strURL.search('@') > 0 )
  147.             strURL = "mailto:" + strURL;
  148.           
  149.           rightText = "<a href='javascript:void(0)' onclick=\"window.open('" + strURL + "')\">" + rightText + "</a>";
  150.         }
  151.       }
  152.       else
  153.       {
  154.         if( typeof( oParam.RightText ) == 'undefined' )
  155.           continue;
  156.         
  157.         rightText = oParam.RightText;
  158.       };
  159.       
  160.       if( typeof( oParam.RightWordWrap ) != 'undefined' && (oParam.RightWordWrap == 0 || oParam.RightWordWrap == "0") )
  161.         rightText = "<NOBR>" + rightText + "</NOBR>";
  162.       
  163.       if( typeof( oParam.RightStyle ) != 'undefined' )
  164.         rightText = oParam.RightStyle + rightText + "</font>";
  165.  
  166.       var newRow = null;
  167.       if( typeof( oParam.Merged ) == 'undefined' || (oParam.Merged != true && oParam.Merged != "true" ) )
  168.         newRow = new Array( new ListCtlCell(leftText, 1), new ListCtlCell(rightText, 1) );
  169.       else
  170.         newRow = new Array( new ListCtlCell(rightText, 2) );
  171.         
  172.       ListObject.Add( newRow );
  173.     };
  174.   };
  175.  
  176.   if( typeof(ListObject.table) == 'undefined' || ListObject.table == null)
  177.     ListObject.Create(document.body);
  178.   else
  179.     ListObject.Show();
  180. }
  181.   
  182. function ShowHTMLProfile( p_oProfile, p_oGroup )
  183. {
  184.   if( typeof( p_oGroup ) != "object" )
  185.     return;
  186.   if( typeof( p_oProfile.url ) == 'undefined' )
  187.     return;
  188.   
  189.   var iFrame = window.frames.hcHTMLProfile;
  190.   if( iFrame == null )
  191.   {
  192.     var frm = document.createElement( "<iframe onload=\"PrepareHtml('" + p_oGroup.id + "');\" name=\"hcHTMLProfile\" width=0 scrolling='no' border='0' frameborder='0' noresize topmargin='0' leftmargin='0' marginheight='0' marginwidth='0'></iframe>")
  193.     document.body.appendChild( frm );
  194.     frm.src = p_oProfile.url;
  195.   }
  196. }
  197.  
  198. function PrepareHtml( p_iID )
  199. {
  200.   var oData = top.hcPersons.document.all[ p_iID ];
  201.   var FieldDefs   = top.hcMain.getFieldsObj();
  202.   if( FieldDefs == null ) return;
  203.   var iFrame = window.frames.hcHTMLProfile;
  204.   var html = iFrame.document.body.innerHTML;
  205.   
  206.   for( var i = 0; i < FieldDefs.children.length; ++i )
  207.   {
  208.     var templateName = "\\[@" + FieldDefs.children[i].name + "@\\]";
  209.     for( var fi = 0; fi < oData.children.length; ++fi )
  210.       if( oData.children[fi].tagName == "PARAM" && oData.children[fi].id == FieldDefs.children[i].id )
  211.       {
  212.         groupValue = oData.children[fi];
  213.         break;
  214.       };
  215.  
  216.     html = html.replace( new RegExp( templateName, "g"), groupValue.name );
  217.   }
  218.   document.body.innerHTML = html;
  219.   
  220.   var oImagesCollection = document.body.getElementsByTagName("IMG");
  221.   if( typeof(oImagesCollection) == 'undefined' || oImagesCollection == null )
  222.     return;
  223.   
  224.   for( var i = 0; i < oImagesCollection.length; ++i )
  225.   {
  226.     oImagesCollection[i].onerror = ImageHider;
  227.   }
  228. }
  229.  
  230. function ImageHider()
  231. {
  232.   event.srcElement.style.visibility = "hidden";
  233. };
  234.